/* 应用全局样式 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: var(--background);
  color: var(--text-color);
  transition: background-color var(--transition-speed) ease;
  min-height: 100vh;
  /* iPhone特定修复 */
  min-height: -webkit-fill-available;
  -webkit-text-size-adjust: 100%;
}

html {
  height: -webkit-fill-available;
}

/* 应用布局 */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: -webkit-fill-available;
  width: 100%;
}

/* 头部样式 */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border-color);
  background-color: var(--card-bg);
  transition: background-color var(--transition-speed) ease;
  position: sticky;
  top: 0;
  z-index: 100;
  /* 支持iPhone动态岛 */
  padding-top: max(var(--space-md), env(safe-area-inset-top));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  background-color: rgba(var(--card-bg-rgb), 0.8);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  text-decoration: none;
  color: var(--text-color);
  font-weight: 600;
}

.logo-icon {
  width: 24px;
  height: 24px;
  background-color: var(--primary-color);
  color: white;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.header-button {
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--border-radius);
  color: var(--text-color);
  transition: background-color var(--transition-speed) ease;
}

.header-button:hover {
  background-color: var(--hover-color);
}

/* 主要内容区域 */
main {
  flex: 1;
  display: flex;
  justify-content: center;
  overflow: hidden;
  padding: var(--space-md);
  /* 支持iPhone的底部手势区域 */
  padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
}

/* 聊天容器 */
.chat-container {
  width: 100%;
  max-width: 800px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--card-bg);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: background-color var(--transition-speed) ease;
}

/* 聊天消息区域 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 6px;
}

/* 空状态 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-color-light);
  padding: var(--space-xl);
}

.empty-state h2 {
  margin-bottom: var(--space-md);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--primary-color);
}

.empty-state p {
  font-size: 1rem;
  line-height: 1.5;
}

/* 输入区域 */
.chat-input {
  padding: var(--space-md);
  border-top: 1px solid var(--border-color);
  transition: border-color var(--transition-speed) ease;
  /* 支持iPhone底部手势区域 */
  padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
  background-color: rgba(var(--card-bg-rgb), 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chat-input form {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background-color: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: calc(var(--border-radius) * 2);
  padding: var(--space-xs) var(--space-sm);
  transition: border-color var(--transition-speed) ease;
}

.chat-input form:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(var(--primary-color-rgb), 0.2);
}

.chat-input input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 1rem;
  padding: var(--space-xs) var(--space-sm);
  color: var(--text-color);
}

.chat-input input::placeholder {
  color: var(--text-color-light);
}

.chat-input input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.send-button {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color var(--transition-speed) ease;
}

.send-button:hover {
  background-color: var(--primary-color-dark);
}

.send-button:active {
  transform: scale(0.95);
}

.send-button:disabled {
  background-color: var(--border-color);
  cursor: not-allowed;
  opacity: 0.7;
  transform: none;
}

/* 思考动画 */
.thinking-animation {
  display: flex;
  gap: 6px;
  padding: var(--space-sm) var(--space-md);
  align-self: flex-start;
  background-color: var(--bot-message-bg);
  border-radius: var(--border-radius-lg);
  margin-top: var(--space-xs);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  animation: fadeIn 0.3s ease-out;
}

.thinking-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--primary-color);
  opacity: 0.6;
  animation: pulse 1.5s infinite ease-in-out;
}

.thinking-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.4;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  header {
    padding: var(--space-sm) var(--space-md);
  }
  
  main {
    padding: var(--space-xs);
  }
  
  .chat-container {
    border-radius: 0;
    border: none;
    max-width: 100%;
  }
}

/* iPhone 14/15 Pro Max特定样式 */
@media only screen and (device-width: 430px) and (device-height: 932px),
       only screen and (device-width: 428px) and (device-height: 926px),
       only screen and (device-width: 390px) and (device-height: 844px),
       only screen and (device-width: 393px) and (device-height: 852px) {
  header {
    padding-top: max(var(--space-sm), env(safe-area-inset-top));
  }
  
  .chat-input {
    padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
  }
  
  main {
    padding-bottom: 0;
  }
}

/* 横屏模式优化 */
@media (orientation: landscape) and (max-height: 500px) {
  header {
    padding: var(--space-xs) var(--space-md);
    padding-left: max(var(--space-md), env(safe-area-inset-left));
    padding-right: max(var(--space-md), env(safe-area-inset-right));
  }
  
  .chat-container {
    max-height: calc(100vh - 60px);
  }
  
  .chat-messages {
    padding: var(--space-sm);
  }
  
  .chat-input {
    padding: var(--space-xs) var(--space-sm);
  }
}
